1 /* 2 * Hunt - a framework for web and console application based on Collie using Dlang development 3 * 4 * Copyright (C) 2015-2017 Shanghai Putao Technology Co., Ltd 5 * 6 * Developer: HuntLabs 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module hunt.view.render; 13 14 import std.stdio; 15 import std.conv; 16 17 import hunt.view; 18 19 alias display = compile_temple; 20 alias display = compile_temple_file; 21 22 CompiledTemple compile_temple_file(string template_file, Filter = void)() 23 { 24 pragma(msg, "Compiling ", template_file, "..."); 25 return compile_temple!(import(template_file), template_file, Filter); 26 } 27 28 CompiledTemple compile_temple(string __TempleString, string __TempleName, __Filter = void)() 29 { 30 //pragma(msg, "Compiling ",__TempleString); 31 const __tsf = (new Parser(__TempleString)).toString; 32 //pragma(msg, "__tsf ",__tsf); 33 mixin(__tsf); 34 alias temp_func = TempleFunc; 35 return CompiledTemple(&temp_func); 36 } 37 38 struct CompiledTemple 39 { 40 alias rend_func = string function(ViewContext,CompiledTemple* ct) @system; 41 public rend_func rf = null; 42 public CompiledTemple* ct = null; 43 this(rend_func rf) 44 { 45 this.rf = rf; 46 } 47 this(rend_func rf , CompiledTemple* ct) 48 { 49 this.rf = rf; 50 this.ct = ct; 51 } 52 string toString(ViewContext ctx) 53 { 54 return this.rf(ctx,this.ct); 55 } 56 CompiledTemple layout(CompiledTemple* ct) 57 { 58 return CompiledTemple(rf,ct); 59 } 60 }